
package IGU;

import com.sun.awt.AWTUtilities;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class Mesas extends javax.swing.JFrame {

    /** Creates new form Mesas */
    public Mesas() {
        setUndecorated(true);
        setResizable(false);
        AWTUtilities.setWindowOpaque(this, false);
        initComponents();
       if( this.dataSource1.getConexion()!=null) System.out.println("mm");
       this.dataSource1.consulta();
       this.dataSource2.consulta();
       this.titleBar1.addCloseAction(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                dispose();
            }
        });
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dataSource1 = new FuenteDeDatos.DataSource();
        dataSource2 = new FuenteDeDatos.DataSource();
        panelNice1 = new org.edisoncor.gui.panel.PanelNice();
        titleBar1 = new org.edisoncor.gui.varios.TitleBar();
        jScrollPane1 = new javax.swing.JScrollPane();
        dataTable1 = new FuenteDeDatos.DataTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        dataTextField1 = new FuenteDeDatos.DataTextField();
        dataTextField2 = new FuenteDeDatos.DataTextField();
        buttonSeven1 = new org.edisoncor.gui.button.ButtonSeven();
        buttonSeven3 = new org.edisoncor.gui.button.ButtonSeven();
        buttonSeven2 = new org.edisoncor.gui.button.ButtonSeven();
        dataCheckBox1 = new FuenteDeDatos.DataCheckBox();

        dataSource1.setCodigosql("select Id_mesa as \"Mesa\" , Ubicacion as \"Ubicación\", Estatus as \"Estatus\" from tbl_mesas;");
        dataSource1.setDb("u164902_SARB");
        dataSource1.setIp("192.168.1.103:3306");
        dataSource1.setPassword("1234");
        dataSource1.setUsuario("orland");

        dataSource2.setCodigosql("select * from tbl_mesas;");
        dataSource2.setDb("u164902_SARB");
        dataSource2.setIp("192.168.1.103:3306");
        dataSource2.setPassword("1234");
        dataSource2.setUsuario("orland");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        titleBar1.setTitulo("Mesas");
        titleBar1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                titleBar1MouseClicked(evt);
            }
        });

        dataTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        dataTable1.setData(dataSource1);
        dataTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dataTable1MouseClicked(evt);
            }
        });
        dataTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dataTable1KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                dataTable1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(dataTable1);

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Numero de Mesa");

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Ubicación");

        dataTextField1.setCampo("Id_mesa");
        dataTextField1.setData(dataSource2);

        dataTextField2.setCampo("Ubicacion");
        dataTextField2.setData(dataSource2);

        buttonSeven1.setText("Nuevo");
        buttonSeven1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSeven1ActionPerformed(evt);
            }
        });

        buttonSeven3.setText("Eliminar");
        buttonSeven3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSeven3ActionPerformed(evt);
            }
        });

        buttonSeven2.setText("Guardar");
        buttonSeven2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSeven2ActionPerformed(evt);
            }
        });

        dataCheckBox1.setForeground(new java.awt.Color(255, 255, 255));
        dataCheckBox1.setText("Activado");
        dataCheckBox1.setCampo("Estatus");
        dataCheckBox1.setData(dataSource2);

        org.jdesktop.layout.GroupLayout panelNice1Layout = new org.jdesktop.layout.GroupLayout(panelNice1);
        panelNice1.setLayout(panelNice1Layout);
        panelNice1Layout.setHorizontalGroup(
            panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(titleBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
            .add(panelNice1Layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                .addContainerGap())
            .add(panelNice1Layout.createSequentialGroup()
                .add(29, 29, 29)
                .add(buttonSeven1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(buttonSeven3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 129, Short.MAX_VALUE)
                .add(buttonSeven2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(33, 33, 33))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, panelNice1Layout.createSequentialGroup()
                .addContainerGap()
                .add(panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(dataCheckBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, panelNice1Layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(29, 29, 29)
                        .add(dataTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, panelNice1Layout.createSequentialGroup()
                        .add(jLabel2)
                        .add(72, 72, 72)
                        .add(dataTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelNice1Layout.setVerticalGroup(
            panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelNice1Layout.createSequentialGroup()
                .add(titleBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 191, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(40, 40, 40)
                .add(panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(dataTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(dataTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(dataCheckBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(38, 38, 38)
                .add(panelNice1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(buttonSeven1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(buttonSeven3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(buttonSeven2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelNice1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelNice1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void titleBar1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titleBar1MouseClicked

    }//GEN-LAST:event_titleBar1MouseClicked

    private void dataTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataTable1KeyPressed
        
    }//GEN-LAST:event_dataTable1KeyPressed

    private void dataTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataTable1KeyReleased
        if(evt.getKeyCode()==evt.VK_UP ||evt.getKeyCode()==evt.VK_DOWN){
            this.dataSource2.setCodigosql("select * from tbl_mesas where Id_mesa= "+this.dataTable1.getModel().getValueAt(this.dataTable1.getSelectedRow(), 0));
            this.dataSource2.consulta();
        }
    }//GEN-LAST:event_dataTable1KeyReleased

    private void dataTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dataTable1MouseClicked
        if(this.dataTable1.getSelectedRow()>-1){
        this.dataSource2.setCodigosql("select * from tbl_mesas where Id_mesa= "+this.dataTable1.getModel().getValueAt(this.dataTable1.getSelectedRow(), 0));
        this.dataSource2.consulta();
        }
    }//GEN-LAST:event_dataTable1MouseClicked

    private void buttonSeven1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSeven1ActionPerformed
        this.dataTextField1.setText("");
        this.dataTextField2.setText("");
    }//GEN-LAST:event_buttonSeven1ActionPerformed

    private void buttonSeven2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSeven2ActionPerformed
       this.dataSource2.consulta("insert into tbl_mesas values("+this.dataTextField1.getText()+",'"+
               this.dataTextField2.getText()+"',"+this.dataCheckBox1.isSelected()+");");
       this.dataSource1.consulta();
    }//GEN-LAST:event_buttonSeven2ActionPerformed

    private void buttonSeven3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSeven3ActionPerformed
     try{
        this.dataSource2.consulta("delete from tbl_mesas where Id_mesa= "+this.dataTextField1.getText());
     }catch(Exception ex){
         System.out.println("llave foranea encontrada");
     }
    }//GEN-LAST:event_buttonSeven3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Mesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Mesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Mesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Mesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Mesas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonSeven buttonSeven1;
    private org.edisoncor.gui.button.ButtonSeven buttonSeven2;
    private org.edisoncor.gui.button.ButtonSeven buttonSeven3;
    private FuenteDeDatos.DataCheckBox dataCheckBox1;
    private FuenteDeDatos.DataSource dataSource1;
    private FuenteDeDatos.DataSource dataSource2;
    private FuenteDeDatos.DataTable dataTable1;
    private FuenteDeDatos.DataTextField dataTextField1;
    private FuenteDeDatos.DataTextField dataTextField2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private org.edisoncor.gui.panel.PanelNice panelNice1;
    private org.edisoncor.gui.varios.TitleBar titleBar1;
    // End of variables declaration//GEN-END:variables
}
